var gulp = require("gulp");
var less = require("gulp-less");
//var sass = require("gulp-sass");
var browserSync = require('browser-sync').create();

// 静态服务器
gulp.task('serve', function() {
    browserSync.init({
        server: {
            baseDir: "./"
        },
        startPath: "./src/index.html"
    });
    
    gulp.watch("./src/*.html", function(){
        browserSync.reload();
    });
});

//定义less编译任务
gulp.task("lessc", function(){
    
    gulp.src("less/*.less")
        .pipe( less() )
        .pipe( gulp.dest("css/") )
    
})

//定义sass编译任务
gulp.task("scss", function(){
    
    gulp.src("scss/*.scss")
        .pipe( sass() )
        .pipe( gulp.dest("css/") )
        .pipe( browserSync.reload({stream: true}) );
    
})

//定义监听任务
gulp.task("watch", function(){
    gulp.watch("less/*.less", ["lessc"]);
//  gulp.watch("scss/*.scss", ["scss"]);
})

gulp.task("default", ["watch",'serve']);

